import { defineStore } from "pinia"

export const useToPro = defineStore("AddToPro", {
    state() {
        return {
            InquireAddToPro: [] as IAddToProduct[],
            BrandList: [] as BrandList[],
            ProductAll: {} as IProductList// 这里是全部需要提交的商品每次下一步都要push进来
        }
    },
    getters: {
        options(state) {
            return state.InquireAddToPro.map(item => {
                return {
                    value: item.name,
                    label: item.name,
                    children: [
                        ...item.children.map(el => {
                            return {
                                value: el.name,
                                label: el.name,
                            }
                        })
                    ]
                }
            })
        },
        BrandListOption(state) {
            return state.BrandList.map(item => {
                return {
                    value: item.name,
                    label: item.name,
                }
            })
        },
    },
    actions: {
        getList(payload: IAddToProduct[]) {
            return this.InquireAddToPro = payload
        },
        getBrandList(payload: BrandList[]) {
            return this.BrandList = payload
        },
        PushData(payload: any) {
            return Object.assign(this.ProductAll, payload)
        }
    }

})